<?php
/*
Overmundo, cultura de todo o Brasil
Desenvolvido pela Tecnopop para o Núcleo de Idéias Movimento
Copyright (C) 2006  Núcleo de Idéias Movimento

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

class_exists('Site') || require('../lib/class.site.php');
class_exists('Overmundo') || require('../lib/class.overmundo.php');
class_exists('Conecta') || require('../lib/class.conecta.php');
class_exists('Usuario') || require('../lib/class.usuario.php');


session_start();
if (!isset($minhaConexao))  {
	$minhaConexao = new Conecta();
}
if (!isset($meuSite)) {
	$meuSite = new Overmundo();
}

if (!isset($meuSite->linkid)) { 
	$meuSite->linkid = $minhaConexao->linkid;
}

$usuarioValido = $meuSite->LimpaCampo($_SESSION["usuarioValido"]);
$lembraUsuario = $_COOKIE["lembraUsuario"];
$hashEsperado = md5($meuSite->ChaveLembra . $lembraUsuario);
if ($hashEsperado != $_COOKIE["hashUsuario"]) {
	$lembraUsuario = 0;
}


if (($usuarioValido) || ($lembraUsuario)) {
	if ($usuarioValido) {
		$usuarioLogado = new Usuario($meuSite->linkid, $usuarioValido);
	} else {
		$usuarioLogado = new Usuario($meuSite->linkid, $lembraUsuario);
	}
	if (($usuarioLogado->PegaStatus() == "ativo") && ($meuSite->OvermundoLiberaNivelParaUsuario($nivelPagina, $usuarioLogado->PegaNivel()))) {
	// nivel liberado

	} else {
		unset($_SESSION['usuarioValido']);
		session_unregister("usuarioValido");
		session_unset("usuarioValido");

		header('location: ../registro/login.php');
		exit();
	}
} else {
	$usuarioLogado = new Usuario($meuSite->linkid);

			
	header('location: ../registro/login.php');
	exit();
}

?>